//
//  UnAMountRightViewController.swift
//  jiaoyi
//
//  Created by wjk on 2018/11/13.
//  Copyright © 2018 wjk. All rights reserved.
//

import UIKit
import PGDatePicker

class UnAMountRightViewController: BaseViewController {
    @IBOutlet var btns1: [UIButton]!
    @IBOutlet var btns2: [UIButton]!
    
    @IBOutlet weak var btnEnd: UIButton!
    @IBOutlet weak var btnStart: UIButton!
    @IBOutlet weak var btn1: UIButton!
    @IBOutlet weak var btn00: UIButton!
    
    @IBOutlet weak var btn11: UIButton!
    var type:String = ""
    
    var state:String = ""
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    
    @IBAction func showStart(_ sender: UIButton) {
        let pic = PGDatePickManager.init()
        pic.datePicker.datePickerMode = .date
        pic.titleLabel.text = "开始时间"
        pic.datePicker.selectedDate = { (dateComponents)->Void in
            let date = NSCalendar.init(calendarIdentifier: .gregorian)?.date(from: dateComponents!)
            let dateFormate = DateFormatter()
            dateFormate.dateFormat = "yyyy-MM-dd"
            let str = dateFormate.string(from: date!)
            self.btnStart.setTitle(str, for: .normal)
        }
        self.present(pic, animated: true) {
            
        }
    }
    
    @IBAction func showEnd(_ sender: UIButton) {
        let pic = PGDatePickManager.init()
        pic.datePicker.datePickerMode = .date
        pic.titleLabel.text = "开始时间"
        pic.datePicker.selectedDate = { (dateComponents)->Void in
            let date = NSCalendar.init(calendarIdentifier: .gregorian)?.date(from: dateComponents!)
            let dateFormate = DateFormatter()
            dateFormate.dateFormat = "yyyy-MM-dd"
            let str = dateFormate.string(from: date!)
            self.btnEnd.setTitle(str, for: .normal)
        }
        self.present(pic, animated: true) {
            
        }
    }
    
    
    @IBAction func seg(_ sender: UIButton) {
        if sender.tag < 4000 {//业务类型
            type = "\(sender.tag - 3000)"
            self.btns1.forEach { (btn) in
                btn.isSelected = false
            }
        }else {//状态
            state = "\(sender.tag - 4000)"
            self.btns2.forEach { (btn) in
                btn.isSelected = false
            }
        }
        sender.isSelected = true
    }
    
    @IBAction func reset(_ sender: Any) {
        self.btnStart.setTitle("请选择开始时间", for: .normal)
        self.btnEnd.setTitle("请选择结束时间", for: .normal)
        self.seg(self.btn00)
        self.seg(self.btn11)
    }
    
    @IBAction func commit(_ sender: UIButton) {
        var data = ["type":type,"status":self.state,"complete_time_begin":"","complete_time_end":""]
        
        if self.btnStart.title(for: .normal) == "请选择开始时间" {
            
        }else {
            data["complete_time_begin"] = self.btnStart.title(for: .normal)
        }
        
        if self.btnEnd.title(for: .normal) == "请选择结束时间" {
            
        }else {
            data["complete_time_end"] = self.btnEnd.title(for: .normal)
        }
        
        
        NotificationCenter.default.post(name: Notification.Name.rightRef2, object: data)
    }
    
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
